import baseUrl from '@/utils/baseUrl.js' // api接口地址
export default {
  data() {
    return {
      currentIndex: 0, //swiper当前
      show: false, //分享弹窗
      info: [], //轮播信息
      background: {
        backgroundColor: 'rgb(67, 70, 103)',
      },
      price: 0, //总价格
      shareInfo: {}, //邀请信息
      percent: 0, //进度
      //icon
      icons: [{
        path: '#',
        imgSrc: 'https://files.yzsheng.com/client/me/img/cheziIcon.png',
        text: '合伙人专属徽章'
      },
      {
        path: '#',
        imgSrc: 'iconcheliang-',
        text: '好友购车分佣'
      },
      {
        path: '#',
        imgSrc: 'iconxiuli',
        text: '好友洗车、保养、维修分佣'
      }
      ],
      //邀请码
      invitationCode: '',
      goLink: ''
    }
  },
  created() {
    this.getUserShareInfo()
    this.getUserStatementInfo()
    this.getCurrentUsersInviteCode()
  },
  //分享给微信好友
  onShareAppMessage: function () {
    let url='/pages_userModule/distriBution/distriBution?code='+ this.invitationCode
    return {
      title: '在吗？100%纯羊毛等你来薅哟~',
      imageUrl: 'https://files.yzsheng.com/client/weixin/fuli.jpg',
      path: url
    }
  },
  methods: {
    lxr() {
      uni.navigateTo({
        url: '/pages_userModule/mobileContacts/mobileContacts?inviteCode=' + this.invitationCode
      })
    },
    frieed() {
      uni.switchTab({
        url: '/pages/friend/friend'
      })
    },
    goPage(url) {
      uni.navigateTo({
        url: url
      })
    },
    //邀请
    async getUserShareInfo() {
      try {
        const res = await this.$api.me.getUserShareInfo()
        this.shareInfo = res.data

        //判断邀请人数是否超过25人
        if (res.data.shareCount > 25) {
          this.percent = 25 * 4
        } else {
          this.percent = res.data.shareCount * 4
        }
        console.log(res.data)
      } catch (err) {}
    },

    //分佣轮播
    async getUserStatementInfo() {
      try {
        const res = await this.$api.me.getUserStatementInfo()
        console.log(res, '分佣')
        this.info = res.data
      } catch (e) {
        //TODO handle the exception
      }
    },

    //获取分享邀请码
    async getCurrentUsersInviteCode() {
      try {
        const res = await this.$api.me.getCurrentUsersInviteCode()
        this.invitationCode = res.data
        if (baseUrl === 'https://testapi.yzsheng.com') {
				  this.goLink = `https://files.yzsheng.com/shareH5/Qmc_Client_H5/index.html?code=${this.invitationCode}&judgeurl=0`
        } else if (baseUrl === 'https://lineapi.yzsheng.com') {
				  this.goLink = `https://files.yzsheng.com/shareH5/Qmc_Client_H5/index.html?code=${this.invitationCode}&judgeurl=1`
        }
      } catch (e) {
        //TODO handle the exception
      }
    },
    //分享微信好友
    goPartner(type) {
      let code = this.invitationCode
      console.log(this.goLink)
      uni.share({
        provider: 'weixin',
        scene: type,
        type: 0,
        summary: '送1000元购车抵用券+39元免费洗车券！点击领取吧',
        title: '在吗？送你1000元购车抵用券',
        href: this.goLink, //这地址太长了，就省略了
        imageUrl: 'https://files.yzsheng.com/client/me/img/logo.png',
        success: function(res) {
          console.log('success:' + JSON.stringify(res))
        },
        fail: function(err) {
          console.log('fail:' + JSON.stringify(err))
          uni.showToast({
            title: '分享失败'
          })
        }
      })
    },
  }
}
